﻿using System.Collections.Generic;
using System.Linq;

namespace Learun.Util
{
    /// <summary>
    /// 版 本 PIT-ADMS V7.0.3 敏捷开发框架
    /// Copyright (c) 2013-2018 Hexagon PPM
    /// 创建人：研发部
    /// 日 期：2017.03.07
    /// 描 述：树结构数据。自带层级结构ChildNodes
    /// </summary>
    public class TreeModel
    {
        /// <summary>
        /// 节点id
        /// </summary>
        public string id { get; set; }
        /// <summary>
        /// 节点显示数据
        /// </summary>
        public string text { get; set; }
        /// <summary>
        /// 节点提示。有时候用于display name，比如属性
        /// </summary>
        public string title { get; set; }
        /// <summary>
        /// 节点数值
        /// </summary>
        public object value { get; set; }
        /// <summary>
        /// 显示图标
        /// </summary>
        public string icon { get; set; }
        /// <summary>
        /// 是否显示勾选框
        /// </summary>
        public bool showcheck { get; set; }
        /// <summary>
        /// 是否被勾选0 for unchecked, 1 for partial checked, 2 for checked
        /// </summary>
        public int checkstate { get; set; }
        /// <summary>
        /// 是否有子节点
        /// </summary>
        public bool hasChildren { get; set; }
        /// <summary>
        /// 是否展开
        /// </summary>
        public bool isexpand { get; set; }
        /// <summary>
        /// 子节点是否已经加载完成了
        /// </summary>
        public bool complete { get; set; }
        /// <summary>
        /// 子节点列表数据
        /// </summary>
        public List<TreeModel> ChildNodes { get; set; }
        /// <summary>
        /// 父级节点ID。比如某个目录下有什么文件
        /// </summary>
        public string parentId { get; set; }

        /// <summary>
        /// 排序
        /// </summary>
        public int? OrderNo { get; set; }

        /// <summary>
        /// 子节点排序
        /// </summary>
        public void OrderChildNodes()
        {
            if (ChildNodes == null || ChildNodes.Count == 0)
            {
                return;
            }
            ChildNodes = ChildNodes.OrderBy(p => p.OrderNo).ToList();
            foreach (var node in ChildNodes)
            {
                node.OrderChildNodes();
            }
        }
        /// <summary>
        /// 扩展数据。比如具体对象的实体类信息
        /// </summary>
        public object NodeExtData { get; set; }

        /// <summary>
        /// 节点类型。比如 0 1 2来代表深度
        /// </summary>
        public string nodeType { get; set; }
    }

    /// <summary>
    /// 轻量化的树结构数据
    /// </summary>
    public class TreeModelLite
    {
        /// <summary>
        /// 节点id
        /// </summary>
        public string id { get; set; }
        /// <summary>
        /// 节点显示数据
        /// </summary>
        public string text { get; set; }

        /// <summary>
        /// 子节点列表数据
        /// </summary>
        public List<TreeModelLite> ChildNodes { get; set; }
        /// <summary>
        /// 父级节点ID。比如某个目录下有什么文件
        /// </summary>
        public string parentId { get; set; } = "0";
    }
}
